package com.yhb.hash.db;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.SQLException;

public class DBProvider2 {
    public <T> T query(String sql, ResultSetHandler<T> rsh, Object... params){
        QueryRunner queryRunner=new QueryRunner(DBCPDataSource.getDataSource());

        T t=null;
        try {
            t=queryRunner.query(sql, rsh,params);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return t;
    }

    public int execute(String sql,Object... params){
        int i=0;
        QueryRunner queryRunner=new QueryRunner(DBCPDataSource.getDataSource());
        try {
            i=queryRunner.execute(sql, params);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return i;
    }
}
